﻿using System;

namespace SPFluid.Core.Validation.Utilities
{
    internal static class MathUtility
    {
        public static bool IsOdd(int value)
        {
            return (value & 1) == 1;
        }

        public static bool IsOdd(long value)
        {
            return (value & 1L) == 1L;
        }

        public static bool IsEven(int value)
        {
            return (value & 1) == 0;
        }

        public static bool IsEven(long value)
        {
            return (value & 1L) == 0L;
        }

        public static bool IsPrime(int value)
        {
            return IsPrime((long)value);
        }

        public static bool IsPrime(long value)
        {
            if (value < 2L)
            {
                return false;
            }

            var num = (int)Math.Sqrt(value);
            for (var index = 2; index <= num; ++index)
            {
                if (value % index == 0L)
                {
                    return false;
                }
            }

            return true;
        } 
    }
}